<template>
  <page-header-wrapper>
    <GlobalSearch :list="searchList" @search="handleSearch" @reset="handleReset"> </GlobalSearch>
    <a-card :bordered="false">
      <s-table ref="table" size="default" :rowKey="(record, index) => index" :columns="columns" :data="loadData">
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
          <a-popconfirm title="确定接入该条数据吗？" @confirm="handleReceive(record)">
            <y-button type="link">接入数据</y-button>
          </a-popconfirm>
          <a-popconfirm placement="bottom" okType="danger" title="确定作废该条数据吗？" @confirm="handleCancel(record)">
            <a-icon :style="{ color: '#f5222d' }" type="close-circle" theme="filled" slot="icon"></a-icon>
            <y-button type="link" class="text-error">网申作废</y-button>
          </a-popconfirm>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { getProposerList } from '@/api/common'
import { getDepartmentInfos } from '@/api/system'
import { postWebToChangeInto, getProposerListWeb, getWeb_NewProposerbyID } from '@/api/communityReviewManagement'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
  },
  data() {
    return {
      RegionNo: '',
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'PrimaryAuditWeb',
        strContent: {},
      },
      searchList: [
        {
          label: '申请编号',
          fields: 'ApplyNO',
          type: 'input',
          props: {
            placeholder: '请输入申请编号',
          },
        },
        {
          label: '申请人姓名',
          fields: 'Proposer',
          type: 'input',
          props: {
            placeholder: '请输入申请人姓名',
          },
        },
        {
          label: '身份证号',
          fields: 'IDcard',
          type: 'input',
          props: {
            placeholder: '请输入身份证号',
          },
        },
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 80,
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '核定保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '操作',
          align: 'center',
          width: 220,
          scopedSlots: { customRender: 'action' },
        },
      ],
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getProposerListWeb(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  created() {
    getDepartmentInfos({
      deptID: this.$store.getters.userInfo.DeptID,
    }).then((res) => {
      this.RegionNo = res.data.PID
    })
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'primaryAuditManagementDetail',
        params: {
          id,
        },
      })
    },
    handleReceive(record) {
      this.$loading.show({
        tip: '正在接入数据中...请等待',
      })
      postWebToChangeInto({
        State: 'add',
        WebIntoModules: {
          ApplyNO: record.ApplyNo,
          ID: record.ID,
          RegionNo: this.RegionNo,
          TownShipNo: this.$store.getters.userInfo.DeptID,
          UserID: this.$store.getters.userid,
          UserName: this.$store.getters.nickname,
        },
      })
        .then((res) => {
          if (res[0].code == 200) {
            this.$message.success('网申数据接入成功')
          } else {
            this.$message.error(res[0].msg)
          }
          this.$refs.table.refresh()
          this.$eventBus.$emit('primaryAuditRefresh')
        })
        .finally(() => {
          this.$loading.hide()
        })
    },
    handleCancel(record) {
      this.$loading.show({
        tip: '网申数据作废中...请等待',
      })
      postWebToChangeInto({
        State: 'WSZF',
        WebIntoModules: {
          ApplyNO: record.ApplyNo,
          ID: record.ID,
          RegionNo: this.RegionNo,
          TownShipNo: this.$store.getters.userInfo.DeptID,
          UserID: this.$store.getters.userid,
          UserName: this.$store.getters.nickname,
        },
      })
        .then((res) => {
          this.$message.success('网申数据作废成功')
          this.$refs.table.refresh()
        })
        .finally(() => {
          this.$loading.hide()
        })
    },
  },
}
</script>
